/*
 * 文件名：ConsumableDaoImpl.java
 * 版权：Copyright by www.wootide.com
 * 描述：
 * 修改人：wuliquan
 * 修改时间：2013-2-25
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */
package com.wootide.cms.service.consumables.consumablesInfo.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.wootide.cms.common.QueryResults;
import com.wootide.cms.log.syslog.RunLog;
import com.wootide.cms.service.consumables.consumablesInfo.dao.ConsumablesTypeInfoDao;
import com.wootide.cms.service.consumables.consumablesInfo.pojo.ConsumablesTypeInfo;
/**
 * 易耗品数据访问层接口实现
 * 〈功能详细描述〉
 * @author wuliquan
 * @version 2013-2-25
 * @see ConsumableDaoTypeImpl
 * @since
 */
public class ConsumablesTypeInfoDaoImpl extends HibernateDaoSupport implements ConsumablesTypeInfoDao
{
    /**
     * 运行日志
     */
    private RunLog runLog;
    
    public int findNumByConsumablesTypeInfoName(String consumablesTypeName)
    {
        runLog.debug("consumablesTypeName=" + consumablesTypeName);
        
        return ((Number)getHibernateTemplate().findByNamedQuery("findConsumablesTypeInfoNumByName",
                consumablesTypeName)
                .get(0)).intValue();
    }

    public ConsumablesTypeInfo findOneConsumablesTypeInfoByConsumablesTypeId(
            Integer consumablesTypeId)
    {
        runLog.debug("consumableTypeId=" + consumablesTypeId);
        
        return getHibernateTemplate().get(ConsumablesTypeInfo.class, consumablesTypeId);
    }
    
    public QueryResults findAllConsumablesTypeInfos()
    {
        QueryResults queryResults = new QueryResults();
        
        queryResults.setResults(getHibernateTemplate().findByNamedQuery("findConsumablesTypeInfos"));
        
        return queryResults;
    }

    @SuppressWarnings("unchecked")
    public ConsumablesTypeInfo findOneConsumablesTypeInfoByName(String consumableTypeName)
    {
        runLog.debug("consumableTypeName=" + consumableTypeName);
        List<ConsumablesTypeInfo> list = getHibernateTemplate().findByNamedQuery("findOneConsumablesTypeInfoByName",consumableTypeName);
        
        return list.isEmpty() ? null : (ConsumablesTypeInfo)list.get(0);
    }

    public void setRunLog(RunLog runLog)
    {
        this.runLog = runLog;
    }
    
}
